/* 
 * $Id$
 *
 * UMKC Robotics 2009
 *
 * This is the driver for the stderr device.
**/

#if defined(WITH_IOSTDERR)



#include <stdio.h>

#include "err.h"
extern int err;

#include "iobase.h"
#include "iopublic.h"
extern BotDevice bdev[];

#include "iostderr.h"

#if defined(WITH_AVRLIBC)
inline int stderr_write(char c, FILE* f) {

  return( err = E_NO_WRITE_CALLBACK );

}
#else
inline int stderr_write() {

  return( err = E_NO_ERROR );

}
#endif

inline int stderr_init() {

#if defined(WITH_AVRLIBC)
  fdev_setup_stream(&bdev[BSTDERR].dev,
                    stderr_write, NULL,
                    _FDEV_SETUP_WRITE );
#else
  bdev[BSTDERR].dev = stderr;
#endif
  return( err = E_NO_ERROR);
}

inline int stderr_destroy() {

#if defined(WITH_AVRLIBC)
  fdev_close(); /* broken? */
#else
  bdev[BSTDERR].dev = (FILE*) NULL;
#endif
  return( err = E_NO_ERROR);
}

inline int stderr_reset() {

  stderr_destroy();
  stderr_init();
  return( err = E_NO_ERROR);

}

#endif /* end ifdef WITH_IOSTDERR */
